import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @Author ufo
 * @Description TODO
 * @Date 2021/1/11 15:58
 * @Version 1.0
 */
public class ZooState {

    public static void main(String[] args) throws IOException, KeeperException, InterruptedException {
        String hostPort = "127.0.0.1:2181";
        String zPath = "/ufo";
        
        List<String> zooChildren = new ArrayList<>();
        //构造ZooKeeper的实例
        ZooKeeper zooKeeper = new ZooKeeper(hostPort, 2000, null);
        try {
            //获取节点下的内容
            zooChildren = zooKeeper.getChildren(zPath,false);
            System.out.println("Znodes of /:");
            for (String zooChild : zooChildren) {
                System.out.println(zooChild);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (KeeperException e) {
            e.printStackTrace();
        }
    }
}
